<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:insert="~{include :: header('修改角色')}" />
	<th:block th:insert="~{include :: ztree-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
		<form class="form-horizontal m" id="form-role-edit" th:object="${role}">
			<input id="roleId" name="roleId" type="hidden" th:field="*{roleId}"/>
			<div class="form-group row" style="margin-top: 30px">
				<label class="col-sm-2 col-form-label text-sm-right">角色名称</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" th:field="*{roleName}" disabled>
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-2 col-form-label text-sm-right">权限字符</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" th:field="*{roleKey}" disabled>
					<span class="help-block m-b-none">控制器中定义的权限字符，如：@RequiresRoles("")</span>
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-2 col-form-label text-sm-right">显示顺序</label>
				<div class="col-sm-3">
					<input class="form-control" type="text" name="sort" th:field="*{sort}">
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-2 col-form-label text-sm-right">备注</label>
				<div class="col-sm-6">
					<input name="remark" class="form-control" type="text" th:field="*{remark}">
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-2 col-form-label text-sm-right">菜单权限</label>
				<div class="col-sm-8">
					<div id="menuTrees" class="ztree"></div>
				</div>
			</div>
		</form>
	</div>
	<th:block th:insert="~{include :: footer}" />
	<th:block th:insert="~{include :: ztree-js}" />
	<script type="text/javascript">
	     $(function() {
			var url = "/menu/roleMenuTreeData?roleId=" + $("#roleId").val();
			var options = {
				id: "menuTrees",
		        url: url,
		        check: { enable: true },
		        expandLevel: 0
		    };
			$.tree.init(options);
		});

		function submitHandler() {
			if ($.validate.form()) {
				var data = $("#form-role-edit").serializeArray();
				var menuIds = $.tree.getCheckedNodes();
				data.push({"name": "menuIds", "value": menuIds});
				$.operate.save("/role/edit.json", data);
			}
	    }
	</script>
</body>
</html>
